import actionTypes from "./actionTypes";
const initState = {
  //门禁审核的table数据
  entrancetableData:{
    data:[],
    count:0,
    total:0
  },
  //student的信息table数据
  studenttableData: {
    data: [],
    count: 0,
    total:0
  },
  //注册审核的table数据
  registertableData:{
    data:[],
    count:0,
    total:0
  },
  devList: [],
  entranceManage: {
    data: [],
    count: 0,
    total:0
  },
  accessRecord: {
    data: [],
    count: 0,
    total:0
  },
  rp:{
    t:0
  },
  canSelectDev: [],
  deptData:[],
  ACCESS_RECORD_DETAIL:[],
  errorstudentData:{
    data:[],
    count:0
  }
};

const entranceReduers = (state = initState, action: any) => {
  switch (action.type) {
    case actionTypes.GET_DEPT_TABLE:
      return{
        ...state,
        deptData: {
          ...action.payload
        }
      };
    case actionTypes.GET_ACCESS_RECORD_DETAIL:
      return{
        ...state,
        ACCESS_RECORD_DETAIL:
            { ...action.payload}
      };
    case actionTypes.GET_ENTRANCE_TABLE:
      return {
        ...state,
        entrancetableData: {
          data: action.payload.data,
          count: action.payload.count
        }
      };

    case actionTypes.GET_STUDENT_INFORMATION_MANAGE_TABLE:
      return {
        ...state,
        studenttableData: {
          data: action.payload.data,
          count: action.payload.count,
          total:action.payload.total
        }
      };

    case actionTypes.GET_DEV_LIST:
      return {
        ...state,
        devList: action.payload.data
      };

    case actionTypes.GET_ACCESS_RECORD:
      return {
        ...state,
        accessRecord: {
          data:action.payload.data,
          count:action.payload.count,
          total:action.payload.total
        }
      };
      //如果注册审核返回成功就把数据存在全局变量里面
    case actionTypes.GET_REGISTER_CHECK_TABLE:
      return{
        ...state,
        registertableData:{
          data:action.payload.data,
          count:action.payload.count,
          total:action.payload.total
        }
      };

    case actionTypes.GET_ENTRANCE_MANAGE_TABLE:
      return {
        ...state,
        entranceManage: {
          data: action.payload.data,
          count: action.payload.count,
          total:action.payload.total
        }
      };

      //如果请求地址数据成功，就会把数据推到tableData
    case actionTypes.GET_STUDENT_ERROR_LIST:
      return{
        ...state,
        errorstudentData:{
          data:action.payload.data,
          count:action.payload.count
        }
      };

    default:
      return state;
  }
};

export default entranceReduers;
